package controllers

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"crypto/md5"
	"encoding/hex"
)

var encryptMd5ViewFunc = func(c *gin.Context) {
	c.HTML(http.StatusOK,"encrypt/md5.twig",TplContext(c));
}

var encryptMd5HandFunc = func(c *gin.Context){
	var form struct{
		Original string `form:"original",json:"original"`
		ChangeType int32 `form:"change_type",json:"change_type"`
	}
	if err := c.ShouldBind(&form);err == nil {
		if form.ChangeType == 0 {
			h := md5.New()
			h.Write([]byte(form.Original))
			rsuccess(c,hex.EncodeToString(h.Sum(nil)))
		} else {
			rsuccess(c, form.Original)
		}
	}else{
		rerror(c)
	}
}